<?php

namespace backend\modules\supplier\models;

use Yii;
use common\models\product\Product;

/**
 * 这个模型基于表 "{{%s_purchase_in_detail}}" 生成。
 *
 * @property integer $id
 * @property string $master_id
 * @property integer $product_id
 * @property integer $product_sn
 * @property string $goods_name
 * @property string $goods_attr
 * @property string $unit
 * @property integer $number
 * @property string $price
 * @property string $remark
 */
class PurchaseInDetail extends \common\models\AR
{
    public $modelName='';
    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%s_purchase_in_detail}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['master_id', 'product_id'], 'required'],
            [['product_id', 'product_sn', 'number'], 'integer'],
            [['price'], 'number'],
            [['master_id'], 'string', 'max' => 15],
            [['goods_name'], 'string', 'max' => 120],
            [['goods_attr', 'remark'], 'string', 'max' => 100],
            [['unit'], 'string', 'max' => 12]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'master_id' => '采购进货单ID',
            'product_id' => '货品ID',
            'product_sn' => '货品编号',
            'goods_name' => '商品名称',
            'goods_attr' => '商品属性',
            'unit' => '包装单位',
            'number' => '数量',
            'price' => '价格',
            'remark' => '备注',
        ];
    }
    
    public function getProduct(){
        return $this->hasOne(Product::className(), ['id' => 'product_id']);
    }
}
